package com.foreknow.dao.impl;

import com.foreknow.dao.RegisterDao;
import com.foreknow.mapping.EntityMapping;
import com.foreknow.mapping.MappingFactory;
import com.foreknow.model.Admin;

import java.sql.SQLException;
import java.util.List;

public class RegisterDaoImpl extends BaseDAO implements RegisterDao {

    @Override
    public boolean setNamePsw(String adminName, String password) throws SQLException {
        String sql = "insert into admin(adminName,password) values(?,?)";
        int i = jdbcTemplate.update(sql,adminName,password);
        return i==1;
    }

    public List<Object> getAll(){
        String sql = "select * from admin";
        EntityMapping mapping = mappingFactory.getMap(MappingFactory.ADMIN_MAPPING);
        List<Object> admins = jdbcTemplate.query(sql,mapping);
//        if (admins.size()>0){
//            Admin admin = (Admin) admins.get(0);
//            return admin;
//        }
        return admins;
    }
}
